#include<iostream>
#include<cstdio>
#include<string>
#include<map>
using namespace std;
map<int,string>mp1;
map<string,int>mp2;
int pd(string str){
	int len=str.size();
	int num=0;
	int tot=1;
	for(int i=0;i<len;i++){
		if(str[i]>='0' && str[i]<='9'){
			if(!num && str[i-1]=='0') return 1;
			else num=num*10+(int)(str[i]-'0');
		}
		else if(str[i]!='.' && str[i]!=':') return 1;
		else if(tot!=4 && str[i]==':') return 1;
		else if(tot==4 && str[i]!=':') return 1;
		else if(num<0 || num>255) return 1;
		else if((str[i]=='.' || str[i]==':') && (str[i-1]<'0' || str[i-1]>'9')) return 1;
		else num=0,tot++;
	}
	if(num<0 || num>65535) return 1;
	else if(tot!=5) return 1;
	else return 0;
}
int main(){
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		string s;
		cin>>s;
		string addr;
		cin>>addr;
		if(pd(addr)) printf("ERR\n");
		else{
			if(s=="Server"){
				if(!mp2[addr]){
					mp1[i]=addr;
					mp2[addr]=i;
					printf("OK\n");
				}
				else printf("FAIL\n");
			}
			else{
				if(mp2[addr]) printf("%d\n",mp2[addr]);
				else printf("FAIL\n");
			}
		}
	}
	return 0;
}
